package org.example.configs;

import org.example.util.JwtAuthInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration  // 声明这是一个Spring配置类
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private JwtAuthInterceptor jwtAuthInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册拦截器并配置规则
        registry.addInterceptor(jwtAuthInterceptor)  // 添加自定义的JWT拦截器   jwtAuthInterceptor是我自定义的拦截器
//                .addPathPatterns("/api/**")         // 拦截所有/api/开头的请求
                .addPathPatterns(
//                        "/user/**",   //上面拦截user所有请求，下面的login就不会通过，也就没有token产生，会报错
                        "/order/**","/cart/**")
                .excludePathPatterns("/user/login",
                        "/user/login/",
                        "/user/register",
                        "/user/register/",
                        "/banner/**",
                        "/category/**",
//                        "/user/findByUsername/**",
                        "/product/**"); // 排除登录接口（不拦截）


    }
}